Linear Diophantine Equations
Introduction
- A linear Diophantine equation is an equation of the form $$ax + by = c$$ where
- $a$, $b$, and $c$ are integers
- $x$ and $y$ are unknown integers
- These equations appear in many places:
- dividing things into groups
- scheduling and timing problems
- puzzles and number tricks
- The Bézout Identity tells us how to write $\gcd(a,b)$ as a combination of $a$ and $b$.
- Now we use that identity to understand when equations like $ax + by = c$ have solutions — and how to find them.
What Is a Linear Diophantine Equation?
- A Diophantine equation is simply an equation where the solutions must be integers.
- A linear Diophantine equation has:
- no powers
- no fractions
- just $ax + by = c$
- Examples:
- $4x + 6y = 14$
- $9x - 5y = 1$
- $2x + 3y = 5$
- The key question:
Does this equation have integer solutions?
This is where the gcd becomes essential.
When Does an Equation \(ax + by = c\) Have Solutions?
A fundamental fact:
- The equation $ax + by = c$ has integer solutions if and only if
- $$\gcd(a,b) \mid c.$$
Meaning:
- Let $d = \gcd(a,b)$.
- If $d$ divides $c$, solutions exist.
- If $d$ does not divide $c$, there are no integer solutions.
Why this is true:
- From Bézout’s Identity, $$ax_0 + by_0 = d.$$
- If $c$ is a multiple of $d$, say $c = kd$, then $$a(kx_0) + b(ky_0) = c.$$
- If $c$ is not a multiple of $d$, no combination of $a$ and $b$ can ever reach $c$.
This gives us a simple test before doing any work.
Finding One Particular Solution
Once we know solutions exist, we need one solution $(x_0, y_0)$.
Steps:
- Compute $d = \gcd(a,b)$.
- Use the extended Euclidean algorithm to find integers $u$ and $v$ such that $$au + bv = d.$$
- Scale both coefficients by $c/d$: $$x_0 = u \cdot \frac{c}{d}, \qquad y_0 = v \cdot \frac{c}{d}.$$
This gives a valid solution to $ax + by = c$.
Example:
- Solve $4x - 7y = 5$.
- Extended Euclid gives $$4(2) + (-7)(1) = 1.$$
- Scaling these by $5/1$ gives $$4(10) + (-7)(5) = 5$$
- So $(x_0, y_0) = (10, 5)$ is a particular solution.
The General Solution: All Integer Solutions
Once we have one solution $(x_0, y_0)$, we can find all solutions.
Let:
- $d = \gcd(a,b)$
- Step vector: $$s_x = \frac{b}{d}, \qquad s_y = -\frac{a}{d}$$
Then every solution has the form: $$x = x_0 + s_x t, \qquad y = y_0 + s_y t$$ where $t$ is any integer.
Interpretation:
- Solutions form a family or line of integer points.
- Changing $t$ moves you along that line.
Example:
- For $4x - 7y = 5$, we found $(10,5)$.
- Since $d=1$, $$s_x = -7, \qquad s_y = -4.$$
- So $$x = 10 - 7t,\qquad y = 5 - 4t.$$
We can rewrite this in a “nicer” form by shifting $t$: $$x = 3 + 7t,\qquad y = 1 + 4t.$$
Special and Degenerate Cases
Case 1: $a = 0$
- Equation becomes $by = c$.
- Solutions exist only if $b \mid c$.
- Then $y = c/b$ and $x$ is free.
Case 2: $b = 0$
- Equation becomes $ax = c$.
- Solutions exist only if $a \mid c$.
- Then $x = c/a$ and $y$ is free.
Case 3: $c = 0$
- Equation is $ax + by = 0$.
- Always solvable.
- Solutions form a line through the origin: $$x = \frac{b}{d}t,\qquad y = -\frac{a}{d}t.$$
These cases are simpler but follow the same principles.
Applications and Connections
Linear Diophantine equations appear in many places:
- Finding modular inverses
- e.g., solving $ax \equiv 1 \pmod{m}$
- Scheduling problems
- e.g., when two repeating events coincide
- Integer partitioning
- e.g., can you make exactly $c$ using coins of sizes $a$ and $b$?
- Number puzzles
- classic “chicken and rabbit” type problems
Summary and Key Ideas
- A linear Diophantine equation is $ax + by = c$ with integer solutions.
- Solutions exist iff $\gcd(a,b)$ divides $c$.
- The extended Euclidean algorithm gives one solution.
- All solutions form a family: $$x = x_0 + \frac{b}{d}t,\qquad y = y_0 - \frac{a}{d}t.$$
- The geometry is simple: integer points on a line.
Calculator
Checking Solutions Exist
- Given a particular equation such as: $6x + 9y = 15$.
- We know a solution exists if: $\gcd(6, 9)\mid 15$.
divides(gcd(6, 9), 15)
Solving an equation
- Finds the solution in the form: $x = x_0 + s_x t, \quad y = y_0 + s_y t$
- Returns values for $x_0$, $s_x$, $y_0$, and $s_y$.
- Values returned are in the nice form, which may differ from the Bézout coefficients.
solveLinearDiophantine(2, 3, 5) solveLinearDiophantine(6, 9, 15)
Exercises
- Determine whether $6x + 9y = 15$ has integer solutions.
- Solve $4x + 6y = 14$.
- Find one solution and then the general solution.
- Find all integer solutions to $9x - 5y = 1$.
- Does the equation $8x + 12y = 7$ have integer solutions?
- Solve $21x + 14y = 7$.
- Give the general solution.
- Find one solution to $35x + 22y = 1$.
- Then write the full family of solutions.
- Solve $2x + 3y = 5$ and express the general solution in the “nicest” form you can.
- Special case: solve $0x + 9y = 27$.
- What does the solution set look like?
- Solve $ax + by = 0$ for $a=12$, $b=18$.
- Give the general solution.